package com.rran.study.designpattern.factory.singleton.enumsingleton;

/**
 * @author yy
 * @Type EnumSington.java
 * @Desc 枚举单例的写法 推荐
 * @date 2020/7/23 10:30
 */
public enum EnumSingleton {
    EnumSingleton;
    private User user = null;

    EnumSingleton() {
        user = new User();
    }

    public User getEnumSingleton() {
        return user;
    }

}

class Test {
    public static void main(String[] args) {
        User singleton = EnumSingleton.EnumSingleton.getEnumSingleton();
        User singleton1 = EnumSingleton.EnumSingleton.getEnumSingleton();
        System.out.println(singleton == singleton1);
    }
}

